import Alert from '@/components/Alert'
import { request } from '@/plugins/axios'
import {
	FetchPlayVideoFile,
	FetchPlayVideoFolder,
	FetchPlayVideoInfoParam,
	FetchPlayVideoParam,
	FetchPostRecordPlayParamsProps,
	ParamsProps,
} from './interface'

/** 获取放像文件夹列表 */
export const fetchGetAllVRSFolders = async () =>
	request<FetchPlayVideoParam<FetchPlayVideoFolder>>({
		url: `/mcc/recorders/play/folders`,
		method: 'get',
	}).then((res) => (res.success ? { list: res.list ?? [], total: res.total ?? 0 } : undefined))

/** 获取放像文件列表 */
export const fetchGetAllVRSFile = async (id: string, params: ParamsProps) =>
	request<FetchPlayVideoParam<FetchPlayVideoFile>>({
		url: `/mcc/recorders/play/folders/${id}`,
		method: 'get',
		params,
	}).then((res) => (res.success ? { list: res.list ?? [], total: res.total ?? 0 } : undefined))

/** 获取会议放像信息 */
export const fetchGetRecordPlayInfo = async (id: string) =>
	request<FetchPlayVideoInfoParam>({
		url: `mcc/${id}/recorders/play`,
		method: 'get',
	}).then((res) => {
		return res.success ? { ...(res.data ?? {}) } : null
	})

/** 开始放像 */
export const fetchPostRecordPlay = async (meetingMoid: string, params: FetchPostRecordPlayParamsProps) =>
	request({
		url: `mcc/${meetingMoid}/recorders/play`,
		method: 'post',
		data: params,
	}).then((res) => {
		if (res.success) {
			return res
		} else {
			res.description && Alert(res.description)
		}
	})

/** 停止放像 */
export const fetchPostRecordStop = async (meetingMoid: string) =>
	request({
		url: `mcc/${meetingMoid}/recorders/play`,
		method: 'DELETE',
	}).then((res) => res)

/** 暂停/恢复放像 */
export const fetchPostRecordPauseOrPlay = async (meetingMoid: string, state: number) =>
	request({
		url: `mcc/${meetingMoid}/recorders/play/state`,
		method: 'put',
		data: { state },
	}).then((res) => res)

/** 调整放像进度 */
export const fetchPostRecordProgress = async (id: string, params: FetchPostRecordPlayParamsProps) =>
	request({
		url: `mcc/${id}/recorders/play/progress`,
		method: 'put',
		data: params,
	}).then((res) => res)
/**
 * 停止会议混音
 * meetingMoid;
 * mixMode 混音模式：1-智能混音;2-定制混音;
 */
export const fetchStopMix = async (meetingMoid: string, mixMode: number) =>
	request({
		url: `mcc/${meetingMoid}/mixs/1?mix_mode=${mixMode}`,
		method: 'DELETE',
	}).then((res) => res)
